package com.all.shiro.service.impl;

import com.all.shiro.model.dto.LoginDto;
import com.all.shiro.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;

/**
 * @Author LY
 * @create 2024/4/3 17:42
 * @Description 用户service
 */
@Slf4j
@Service
public class SysUserServiceImpl implements ISysUserService {

    @Override
    public void login(LoginDto dto) {
        log.info("校验用户 ===>>>");
        UsernamePasswordToken token = new UsernamePasswordToken(dto.getUsername(), dto.getPassword());
        Subject subject = SecurityUtils.getSubject();
        // 调用realm的认证方法
        subject.login(token);
        // 设置session失效时间：永不超时
        subject.getSession().setTimeout(-1001);
    }
}
